package lgq.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lgq.service.CourseScoreManager;
import lgq.service.EmpManager;
import model.CourseScore;
import model.Emp;
import model.TrainCourse;

public class UpdateTrainScoreServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int empid=Integer.parseInt(request.getParameter("empid"));
		//int trainid=Integer.parseInt(request.getParameter("trainid"));
		String score[]=request.getParameterValues("score");
		String traincourseid[]=request.getParameterValues("traincourseid");
		Emp emp=new EmpManager().getById(empid);
		TrainCourse tc=new TrainCourse();
		
		CourseScoreManager csm=new CourseScoreManager();
		for(int i=0;i<score.length;i++)
		{
			tc.setId(Integer.parseInt(traincourseid[i]));
			System.out.println(score[i]);
			//System.out.println(trainid);
			CourseScore cs=new CourseScore();
			cs.setEmp(emp);
			cs.setTrainCourse(tc);
			cs.setScore(Double.parseDouble(score[i]));
			csm.updateCourseScore(cs);
		}
		request.getRequestDispatcher("/FindTrainScore").forward(request, response);
	}

}
